package com.qfedu.controller;

import com.github.wxpay.sdk.WXPayUtil;
import com.qfedu.entity.Orders;
import com.qfedu.entity.ResultVo;
import com.qfedu.service.OrderService;
import com.qfedu.vo.TokenVo;
import com.qfedu.websocket.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/getOrderToken")
    public ResultVo getOrderToken(){
        return  orderService.getOrderToken();
    }

    @GetMapping("/reserve")
    public ResultVo reserve(Integer productId,Integer skuId,Integer dateId){
        return orderService.reserve(productId, skuId,dateId);
    }

    @PostMapping("/saveOrder")
    public ResultVo saveOrder(@RequestBody Orders orders,
                              @RequestHeader("token") String  token,
                              @RequestHeader("orderToken")String orderToken){
        ResultVo vo = orderService.saveOrder(orders, new TokenVo(token, orderToken));
        return vo;
    }

    @GetMapping("/selectOrder")
    public ResultVo selectOrder(String orderId){
        return orderService.selectOrder(orderId);
    }

    @GetMapping("/getPay")
    public ResultVo pay(String orderId){
        return orderService.getPay(orderId);
    }



}
